(function(window) {
	//为构造函数加一个计数器，根据调用的个数来决定图片个数及位置
	backGround.count = 0;
	
	/*
	 *参数是一个对象，需要两个属性及属性值
	 * 1,绘制环境 ctx;
	 * 2,需要绘制的图片对象img;
	 * 
	 * */
	function backGround(options) {
		backGround.count++;
		this.ctx = options.ctx;
		this.img = options.img;

		//计算背景图的宽高
		this.width = this.img.width;
		this.height = this.img.height;

		//起始位置
		this.x = this.width * (backGround.count - 1);
		this.y = 0;

		// 背景每秒运行的速度
		this.speedSecond = 40;
	}
	backGround.prototype = {
		constructor: backGround,
		draw: function() {
			this.ctx.drawImage(this.img, this.x, this.y);
		},
		//更新x轴坐标，让背景图动起来
		update: function(delaySecond) {
			//x坐标为速度*时间
			this.x -= this.speedSecond * delaySecond;
			if(this.x <= -this.width) {
				this.x += this.width * backGround.count;
			}
		}
	}
	window.backGround = backGround;
}(window))